package com.yjx.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Password {
    private static String SALT = "hunankejidaxue";

    public static String generateMD5(String input){
        try {
            String saltedInput = SALT + input + SALT;
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] hashBytes = md.digest(saltedInput.getBytes());

            StringBuilder sb = new StringBuilder();
            for(byte b : hashBytes) {
                sb.append(String.format("%02x", b));
            }
            return sb.toString();
        }
        catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("MD5 algorithm not found", e);
        }
    }
}
